package com.bigdatastudio.auth.serverImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bigdatastudio.auth.mapper.RoleMapper;
import com.bigdatastudio.auth.server.IUserRoleService;
import com.bigdatastudio.common.entity.Role;
import com.bigdatastudio.common.entity.UserRole;
import com.bigdatastudio.auth.server.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Autowired
    IUserRoleService userRoleService;

    @Autowired
    IRoleService iRoleService;

    @Override
    public List<Role> listRolesByUserId(int userId) {
        List<Integer> rids = userRoleService.getRoleIdsByUserId(userId)
                .stream().map(UserRole::getRoleId).collect(Collectors.toList());
        return iRoleService.listByIds(rids);
    }
}
